package cc.wd.demo.blockchain;

import cc.wd.demo.blockchain.model.*;
import cc.wd.demo.blockchain.utils.SecureUtil;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.security.NoSuchAlgorithmException;
import java.util.HashMap;

/**
 * @author al
 */
@SpringBootApplication
public class BlockChainApplication {

    public static HashMap<String,TransactionOutput> UTXOs = new HashMap<>(); //未使用的输出集合
    public static float minimumTransaction = 0.1f;


    public static void main(String[] args) throws NoSuchAlgorithmException {
//        SpringApplication.run(BlockChainApplication.class, args);

        BlockChain blockChain = BlockChain.getInstance();

        Block first = blockChain.add("first");
        Block second = blockChain.add("second");
        Block third = blockChain.add("third");
        Block four = blockChain.add("four");

        blockChain.printChain();

        if (!blockChain.chainValid()) {
            throw new RuntimeException();
        }

        //创建两个钱包
        Wallet walletA = new Wallet();
        Wallet walletB = new Wallet();
        //测试公钥和私钥
        System.out.println("Private and public keys:");
        System.out.println(SecureUtil.getStringFromKey(walletA.getPrivateKey()));
        System.out.println("======================== public ==================");
        System.out.println(SecureUtil.getStringFromKey(walletA.getPublicKey()));
        //创建一个交易从WalletA地址到walletB地址
        Transaction transaction = new Transaction(walletA, walletB, 5, null);
//        Wallet walletC = new Wallet();
//        transaction.sender = walletC;

        //通过wallectA的公钥验证签名是否工作
        System.out.println("Is signature verified");
        System.out.println(transaction.verifySignature());


    }


}
